package cn.wanda.bi.sunshine.platform.server.config;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.ffan.soa.platform.common.config.SwaggerApiInfo;

import feign.Logger;
import springfox.documentation.service.Contact;

/**
 * Created by wangfupeng1
 */
@Configuration
public class CommonConfig {

	@Value("${threadpooltaskexecutor.corepoolsize}")
	private String corepoolsize;
	@Value("${threadpooltaskexecutor.maxpoolsize}")
	private String maxpoolsize;
	@Value("${threadpooltaskexecutor.queuecapacity}")
	private String queuecapacity;
	@Value("${threadpooltaskexecutor.keepaliveseconds}")
	private String keepaliveseconds;
	@Value("${threadpooltaskexecutor.threadnameprefix}")
	private String threadnameprefix;


	@Bean
	Logger.Level feignLoggerLevel() {
		return Logger.Level.FULL;
	}

	@Bean
	public SwaggerApiInfo swaggerApiInfo() {
		SwaggerApiInfo info = new SwaggerApiInfo("大万达", "大千帆营销服务", "1.0", "url",
				new Contact("{wangfupeng1,wangxiaoling18,lijingtao5}", "http://", ""),
				"Licensed under the Apache License, Version 2.0", "http://www.apache.org/licenses/LICENSE-2.0");
		return info;
	}

	@Bean
	public Executor threadPoolTaskExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(Integer.valueOf(corepoolsize));
		executor.setMaxPoolSize(Integer.valueOf(maxpoolsize));
		executor.setQueueCapacity(Integer.valueOf(queuecapacity));
		executor.setKeepAliveSeconds(Integer.valueOf(keepaliveseconds));
		executor.setThreadNamePrefix(threadnameprefix);
		executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		executor.initialize();
		return executor;
	}

}
